import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

class ImageUtils {
  ImageUtils._();

  /// 加载图片
  static imageLoad(String? image, {double? width = 28, double? height = 28}) {
    if (image == null || image == "") {
      return SizedBox();
    }
    if (image.contains("http")) {
      return Image.network(
        image,
        width: width,
        height: height,
        fit: BoxFit.fill,
        errorBuilder: (context, error, stackTrace) {
          return Container(
            width: width,
            height: height,
            decoration: BoxDecoration(color: Colors.transparent),
          );
        },
      );
    } else {
      return Image.asset(image, width: width, height: height, fit: BoxFit.fill);
    }
  }

  static asset(String? image, {double? width, double? height, BoxFit? fit}) {
    if (image == null || image == "") {
      return SizedBox();
    }
    return Image.asset(image, width: width, height: height, fit: fit);
  }

  /// 加载svg
  static assetSvg(String assetName,
      {double? width, double? height, Color? color, String? semanticsLabel}) {
    return SvgPicture.asset(assetName,
        width: width,
        height: height,
        color: color,
        semanticsLabel: semanticsLabel);
  }
}
